#pragma comment(linker,"/STACK:100000000")
#include "testlib.h"
#include <stdio.h>
#define N 1010
int m[N][N], a[N], b[N], ua[N], ub[N];
int main(int argc, char * argv[])
{
    registerTestlibCmd(argc, argv);
    int n, k, i, j;
	n=inf.readInt();
	k=inf.readInt();
	for(; k--; i=inf.readInt()-1, j=inf.readInt()-1, m[i][j]=1);
	n=ans.readInt();
	k=ouf.readInt();
	if(n!=k) quitf(_wa, "wrong number of pairs: expected %d, found %d", n, k);
	else
	{
		for(k=0; k<n; k++)
		{
			i=ouf.readInt()-1;
			j=ouf.readInt()-1;
			if(!m[i][j]) quitf(_wa, "There is no edge %d, %d", i+1, j+1);
			if(ua[i]) quitf(_wa, "wrong matching: left vertex %d is already matched", i+1);
			if(ub[j]) quitf(_wa, "wrong matching: right vertex %d is already matched", j+1);
			ua[i]=1;
			ub[j]=1;
			a[k]=i;
			b[k]=j;
		}
		for(k=0; k<n; k++)
		{
			i=ans.readInt()-1;
			j=ans.readInt()-1;
			if(i<a[k]) quitf(_wa, "matching is not lexicographically minimal");
			if(i>a[k]) quitf(_fail, "jury's matching is not lexicographically minimal");
			if(j<b[k]) quitf(_wa, "matching is not lexicographicaly minimal");
			if(j>b[k]) quitf(_fail, "jury's matching is not lexicographically minimal");
		}
	}
	quitf(_ok, "%d pairs", n);
}